<template>
  <div class="select">
        <el-autocomplete
            class="inline-input"
            v-model="input"
            style="width: 100%"
            :fetch-suggestions="querySearch"
            placeholder="点击此处搜素店铺"
            @select="handleSelect"
            clearable
        ></el-autocomplete>
  </div>

</template>
<script>
//引入保存数据的函数
import {priceFun, shopFun} from "@/js/featuresApi";
import {EventBus} from "@/main";
export default {
  name: "MySelect",
  data() {
    return {
      restaurants: [],
      input: '',
    }
  },
  methods: {
    //搜索查询功能
    handleSelect(item) {
      //将搜索框中商店名称传出
      shopFun(function (data) {
        let arr = [];
        for (let i = 0; i < data.result.features.features.length; i++) {
          if (data.result.features.features[i].properties.NAME === item.value) {
            var lat = data.result.features.features[i].properties.LAT;
            var lng = data.result.features.features[i].properties.LNG;
            arr.push(lat);
            arr.push(lng);
            var id = data.result.features.features[i].properties.超市ID;
          }
        }
        //将结果超市点经纬度传给BaseMap组件使用
        EventBus.$emit('center',arr);
        // EventBus.$emit('input',this.input);
        //筛选符合要求的超市，并弹窗展示商品信息
        priceFun(function (data) {
          new L.supermap.GetFeaturesByIDsParameters({
            IDs: [id],
            datasetNames: ["ChengduFresh:Price"]
          });
          let food = [];
          let price = [];
          //筛选符合要求的超市，并弹窗展示商品信息
          for (let i = 0; i < data.result.features.features.length; i++) {
            if (data.result.features.features[i].properties.超市ID === id) {
              food.push(data.result.features.features[i].properties.品类)
              price.push(data.result.features.features[i].properties.价格元KG)
            }
          }
          EventBus.$emit('item', item.value);
          EventBus.$emit('food', food);
          EventBus.$emit('price', price);
          EventBus.$emit('count', food.length);
        })
      });
    },
    querySearch(queryString, cb) {
      let restaurants = this.restaurants;
      let results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      };
    },
    loadAll() {
      return [
        {"value": "组合生鲜(荆竹店)", "address": "成华区"},
        {"value": "众惠生鲜超市", "address": "青羊区"},
        {"value": "至胜客生鲜百货超市", "address": "金牛区"},
        {"value": "正通生鲜果蔬", "address": "武侯区"},
        {"value": "优鲜家生鲜超市", "address": "成华区"},
        {"value": "优美惠生鲜超市(龙腾店)", "address": "武侯区"},
        {"value": "盈地生鲜超市", "address": "成华区"},
        {"value": "谊品生鲜(新桥逸景店)", "address": "金牛区"},
        {"value": "谊品生鲜(田园锦绣)", "address": "武侯区"},
        {"value": "谊品生鲜(水木光华店)", "address": "青羊区"},
        {"value": "益园生鲜", "address": "青羊区"},
        {"value": "益民生鲜市场", "address": "锦江区"},
        {"value": "益民生鲜超市", "address": "金牛区"},
        {"value": "亿森源生鲜超市(蓝光COCO国际连锁店)", "address": "成华区"},
        {"value": "亿森源生鲜超市(锦绣东方店)", "address": "成华区"},
        {"value": "亿多生鲜", "address": "金牛区"},
        {"value": "壹伍壹拾生鲜超市", "address": "武侯区"},
        {"value": "一加生鲜(武阳大道店)", "address": "武侯区"},
        {"value": "玄乐平台生鲜订购提货点", "address": "武侯区"},
        {"value": "宣宣生鲜超市", "address": "成华区"},
        {"value": "轩轩鲜生鲜超市", "address": "成华区"},
        {"value": "信义利青清源生鲜超市(金祥路店)", "address": "青羊区"},
        {"value": "鑫锴福生鲜超市", "address": "金牛区"},
        {"value": "鑫欢生鲜超市", "address": "武侯区"},
        {"value": "馨怡家生鲜超市", "address": "金牛区"},
        {"value": "蟹小姐节气生鲜(合江亭店)", "address": "锦江区"},
        {"value": "蟹小姐节气生鲜(成华店)", "address": "成华区"},
        {"value": "小张生鲜店", "address": "武侯区"},
        {"value": "小宇哥生鲜超市", "address": "武侯区"},
        {"value": "小杨生鲜", "address": "成华区"},
        {"value": "小时生鲜", "address": "武侯区"},
        {"value": "乡邻生鲜超市", "address": "成华区"},
        {"value": "乡间味生鲜果蔬(中央华城2店)", "address": "成华区"},
        {"value": "鲜悦时光果蔬生鲜店", "address": "成华区"},
        {"value": "鲜百汇生鲜超市", "address": "金牛区"},
        {"value": "物宝生鲜", "address": "锦江区"},
        {"value": "武侯新城盒马鲜生", "address": "武侯区"},
        {"value": "五尚生鲜(元华店)", "address": "武侯区"},
        {"value": "窝窝生鲜", "address": "武侯区"},
        {"value": "万家生鲜超市(泉水店)", "address": "金牛区"},
        {"value": "万泓惠民生鲜小店", "address": "金牛区"},
        {"value": "碗里生鲜超市", "address": "青羊区"},
        {"value": "同鑫生鲜超市(连锁)直营店", "address": "金牛区"},
        {"value": "甜酒生鲜", "address": "青羊区"},
        {"value": "田园生鲜超市", "address": "成华区"},
        {"value": "田园果蔬生鲜超市(总店)", "address": "成华区"},
        {"value": "田村长生鲜超市", "address": "锦江区"},
        {"value": "天天生鲜超市(锦里西路店)", "address": "青羊区"},
        {"value": "天天来生鲜", "address": "武侯区"},
        {"value": "天客隆生鲜超市", "address": "锦江区"},
        {"value": "涛北生鲜", "address": "武侯区"},
        {"value": "蒜苗生鲜", "address": "成华区"},
        {"value": "苏来生鲜苏来便利", "address": "武侯区"},
        {"value": "四季生鲜", "address": "成华区"},
        {"value": "蜀明生鲜超市", "address": "金牛区"},
        {"value": "蜀地农生鲜超市", "address": "武侯区"},
        {"value": "时时鲜生鲜超市", "address": "锦江区"},
        {"value": "时惠生鲜", "address": "成华区"},
        {"value": "生鲜之家(沙河源店)", "address": "金牛区"},
        {"value": "生鲜之家", "address": "金牛区"},
        {"value": "生鲜意佰", "address": "金牛区"},
        {"value": "尚品生鲜", "address": "武侯区"},
        {"value": "上品生鲜", "address": "青羊区"},
        {"value": "山顶石生鲜", "address": "锦江区"},
        {"value": "森林八戒生鲜连锁", "address": "成华区"},
        {"value": "三汇生鲜", "address": "成华区"},
        {"value": "三和生鲜", "address": "成华区"},
        {"value": "人人乐生鲜超市", "address": "成华区"},
        {"value": "青清源生鲜超市", "address": "成华区"},
        {"value": "青青源生鲜超市(双锦路店)", "address": "青羊区"},
        {"value": "普惠连锁生鲜超市", "address": "成华区"},
        {"value": "品优生鲜", "address": "成华区"},
        {"value": "沛洁生鲜", "address": "武侯区"},
        {"value": "鸥玛特生鲜超市", "address": "金牛区"},
        {"value": "年年有鱼生鲜", "address": "金牛区"},
        {"value": "米先森生鲜店", "address": "金牛区"},
        {"value": "麦青生鲜(新乐路农贸店)", "address": "武侯区"},
        {"value": "麦哆哆社区生鲜超市文德店", "address": "成华区"},
        {"value": "妈妈鲜生鲜超市", "address": "金牛区"},
        {"value": "绿优优生鲜", "address": "成华区"},
        {"value": "绿优鲜生鲜店", "address": "武侯区"},
        {"value": "绿美鲜生鲜折扣店", "address": "青羊区"},
        {"value": "绿果生鲜(长庆西一路店)", "address": "金牛区"},
        {"value": "绿地生鲜", "address": "成华区"},
        {"value": "林桓生鲜超市", "address": "成华区"},
        {"value": "良果鲜生生鲜超市", "address": "金牛区"},
        {"value": "联禾利民生鲜", "address": "金牛区"},
        {"value": "利蓉生鲜", "address": "金牛区"},
        {"value": "立优鲜生鲜超市", "address": "锦江区"},
        {"value": "乐购生鲜(府河店)", "address": "金牛区"},
        {"value": "老马路生鲜店(红瓦寺店)", "address": "武侯区"},
        {"value": "老兵惠民生鲜超市", "address": "金牛区"},
        {"value": "坤坤生鲜", "address": "武侯区"},
        {"value": "客家人生鲜超市", "address": "金牛区"},
        {"value": "科文生鲜", "address": "金牛区"},
        {"value": "康倍乐生鲜家禽店", "address": "金牛区"},
        {"value": "聚源泰生鲜超市连锁服务点", "address": "青羊区"},
        {"value": "锦家生鲜超市", "address": "成华区"},
        {"value": "金牛区舒妍生鲜超市", "address": "金牛区"},
        {"value": "今达乐生鲜", "address": "金牛区"},
        {"value": "建国生鲜", "address": "武侯区"},
        {"value": "家园生鲜雅安猪肉", "address": "武侯区"},
        {"value": "家乡美生鲜超市", "address": "武侯区"},
        {"value": "家家旺生鲜", "address": "锦江区"},
        {"value": "极生鲜(长寿路店)", "address": "武侯区"},
        {"value": "吉佰家生鲜超市", "address": "武侯区"},
        {"value": "惠普生鲜", "address": "锦江区"},
        {"value": "惠邻生鲜超市", "address": "成华区"},
        {"value": "惠白莲生鲜店", "address": "成华区"},
        {"value": "汇美生鲜店", "address": "金牛区"},
        {"value": "汇百佳生鲜(站北农贸店)", "address": "成华区"},
        {"value": "红姐生鲜", "address": "武侯区"},
        {"value": "恒然鲜净菜生鲜店(双丰路店)", "address": "武侯区"},
        {"value": "禾叶生鲜", "address": "青羊区"},
        {"value": "浩萱生鲜超市", "address": "成华区"},
        {"value": "憨农菲尔德生鲜超市(光明路店)", "address": "锦江区"},
        {"value": "海之源优品生鲜超市", "address": "武侯区"},
        {"value": "果蔬生鲜店", "address": "青羊区"},
        {"value": "果蔬生鲜", "address": "青羊区"},
        {"value": "广润生鲜(财大店)", "address": "青羊区"},
        {"value": "广评生鲜(万象城店)", "address": "成华区"},
        {"value": "方钰辉生鲜超市", "address": "锦江区"},
        {"value": "多宜佳生鲜超市", "address": "青羊区"},
        {"value": "地利生鲜(一品天下店)", "address": "金牛区"},
        {"value": "初新生鲜", "address": "锦江区"},
        {"value": "虫虫菜蓝子生鲜坊", "address": "锦江区"},
        {"value": "菜园坝生鲜火锅食材", "address": "金牛区"},
        {"value": "菜果生鲜", "address": "武侯区"},
        {"value": "菜公社生鲜站(新牛沙综合市场店)", "address": "锦江区"},
        {"value": "彩芸生鲜火锅超市(交桂巷店)", "address": "金牛区"},
        {"value": "便捷生鲜", "address": "武侯区"},
        {"value": "贝壳生鲜", "address": "成华区"},
        {"value": "豹宇生鲜(点将台店)", "address": "锦江区"},
        {"value": "霸王送菜生鲜熟食(玉林店)", "address": "武侯区"},
        {"value": "爱鲜爱厨生鲜超市(红花村店)", "address": "金牛区"},
        {"value": "爱鲜爱厨生鲜超市(东光店)", "address": "锦江区"},
        {"value": "爱到生鲜超市", "address": "金牛区"},
        {"value": "V客生鲜超市", "address": "锦江区"},
        {"value": "U鲜到家生鲜", "address": "青羊区"},
        {"value": "e家生鲜超市(成都和安二路店)", "address": "成华区"},
        {"value": "A+生鲜(交大路店)", "address": "金牛区"},
        {"value": "9号生鲜", "address": "成华区"},

      ]
    },
  },
  mounted() {
    this.restaurants = this.loadAll();
    //清除搜索框内容
    EventBus.$on('input',(data)=>{
      this.input = data
    })
  },
}
</script>
<style scoped>
.select {
  z-index: 10;
  position: absolute;
  width: 18%;
  right: 3%;
  top: 8%;
  border: 2px solid black;
  border-radius: 5px;
}

</style>